package org.lanqiao.dxzf.controller.report;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import org.lanqiao.dxzf.entity.Report;
import org.lanqiao.dxzf.service.report.ReportService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ReportController {
	@Resource
	ReportService reportService;
	/**
	 * 报表-->>查询报表的所有的信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/report_list.do")
	public String report_list(HttpServletRequest request) {
		int totalRecord = reportService.selectCount();
		int pageSize  =  5;
		int currentPage = -1;
		String curPage = request.getParameter("currentPage");
		if(curPage==null)
			currentPage=1;
		else
			currentPage=Integer.parseInt(curPage);  
		int pageCount = (totalRecord%pageSize==0)?(totalRecord/pageSize):(totalRecord/pageSize+1);
        int a = (currentPage-1)*pageSize;
		
        request.setAttribute("totalRecord", totalRecord);
        request.setAttribute("pageSize", pageSize);
        request.setAttribute("currentPage", currentPage);
        request.setAttribute("pageCount", pageCount);
        request.setAttribute("a", a);
		 
		List<Report> report = reportService.listReport(a);
		request.setAttribute("report", report);
		 return "report/report_list";
	}
	/**
	 * 报表-->>查询所有的报表信息根据时间排序
	 * @return
	 */
	@RequestMapping("/reportTimeDesc.do")
	public String reportTimeDesc(HttpServletRequest request) {
		List<Report> report = reportService.listTimeDesc(null);
		request.setAttribute("report", report);
		return "report/report_list";
	}
}
